package com.liwujie.controller;


import com.liwujie.common.order.OrderConfirmVO;
import com.liwujie.context.UserContext;
import com.liwujie.core.bean.ResultBean;
import com.liwujie.core.controller.BaseController;
import com.liwujie.dto.OrderDTO;

import com.liwujie.service.IOrderService;
import com.liwujie.token.AuthUserContext;
import com.liwujie.token.TokenTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 订单信息 前端控制器
 * </p>
 *
 * @author liwujie
 * @since 2025-04-14
 */
@RestController
@Primary // 标记为首选Bean
@RequestMapping("/api/order")
@Api(tags = "订单接口")
public class OrderController extends BaseController {

    @Autowired
    private IOrderService orderService;

    private TokenTemplate tokenTemplate;


    @PostMapping("/Confirm")
    @Validated
    @ApiOperation(value = "保存订单确认信息", notes = "返回订单确认页所需数据")
    public ResultBean<OrderConfirmVO> Confirm(@Valid @RequestBody OrderDTO orderDTO ) {
        Long userId = UserContext.get().getUserId();
        OrderConfirmVO rs = orderService.confirmOrder(userId, orderDTO);

        return success("订单确认成功", rs);
    }

    @PostMapping("/submit")
    @Valid
    @ApiOperation(value = "提交订单", notes = "提交订单")
    public  ResultBean<Long> submit(){
        Long userId = UserContext.get().getUserId();

        String rs = orderService.submitOrder(userId);

        return success("订单提交成功", rs);
    }






}
